package com.example.paopao.consumer.memer.alipay.dao.persist.repository.impl;

import com.example.paopao.consumer.memer.alipay.dao.persist.mapper.PayIntegralMapper;
import com.example.paopao.consumer.memer.alipay.dao.persist.repository.IPayIntegralRepository;
import com.example.paopao.consumer.memer.alipay.pojo.entity.IntegralRacharge;
import com.example.paopao.consumer.memer.alipay.pojo.po.AccountPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class PayIntegralRepositoryImpl implements IPayIntegralRepository {

    @Autowired
    private PayIntegralMapper mapper;

    @Override
    public int insertIntegral(IntegralRacharge integralRacharge) {
        return mapper.insert(integralRacharge);
    }

    @Override
    public int updateAccount(AccountPO account) {
        AccountPO accountPO = mapper.selectAccount(account.getUserId());
        if (accountPO==null){
            accountPO.setBalance(0);
        }
        account.setBalance(accountPO.getBalance() + account.getBalance());
        int i = mapper.updateAccount(account);
        return i;
    }
}
